// pages/not_order_details/details.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: {},
    order: {},
    text: '去支付',
    status: false,//状态
    imgUrl: '',//图片地址
    orderId: 0,//订单id
  },

  /**
   * 支付
   */
  pay() {
    if (this.data.list.type == 2) {
      wx.navigateTo({
        url: '../../pages/balance-store/store?billId=' + this.data.orderId,
      })
    } else {
      wx.navigateTo({
        url: '../../pages/side_food/food?billId=' + this.data.orderId,
      })
    }
    console.log(this.data.list.type)
  },

  /**
   * 查询订单详情
   */
  getOrderDetail(id) {
    console.log(id)
    let _this = this
    app.gets(app.url.order.detail + '?billHisId=' + id).then(re => {
      let goods = []
      let sum = 0.0
      let order = {
        time: re.data.billHisLine[0].CONTIME,
        feel: re.data.billHisLine[0].BILL_CODE,
      }
      re.data.billHisLine.forEach(item => {
        sum += item.TOTAL_PRICE
        let good = {
          img: item.IMAGE_URL,
          name: item.NAME,
          sum: item.FOOD_NUM,
          price: item.TOTAL_PRICE / item.FOOD_NUM
        }
        console.log(sum)
        goods.push(good)
      })
      let list = {
        shop_name: re.data.billHisLine[0].resName,
        type: re.data.billHisLine[0].TYPE,
        goods: goods,
        mild: re.data.billHisLine[0].REAL_MONEY
      }
      console.log(re.data)
      _this.setData({
        list: list,
        imgUrl: re.data.urls,
        order: order
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options.id)
    this.setData({
      status: options.status,
      orderId: options.id
    })
    this.getOrderDetail(options.id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})